
def xtree(data):
    if not data:
        return data
    tree={}
    list=[]
    for i in data:
        tree[i['id']]=i
    for j in data:
        pid=j['pid']
        if pid==0:
            list.append(j)
        else:
            if 'son'not in tree[pid]:
                tree[pid]['son']=[]
            tree[pid]['son'].append(j)
    return list